from rest_framework import serializers

from areas.models import Area


class AreaViewSerializer(serializers.ModelSerializer):
    '''省级地区查询序列化器'''

    class Meta:
        model = Area
        fields = ('id', 'name')


class SubsViewSerializer(serializers.ModelSerializer):
    '''指定地区查询序列化器'''

    # 指定关联嵌套使用的序列化器,将下级地区也进行序列化
    subs = AreaViewSerializer(label='下级地区', many=True)

    class Meta:
        model = Area
        fields = ('id', 'name', 'subs')
